
local mt = {}
mt.__index = mt

local stty = function(args)
	os.execute([[stty ]] .. args)
end

local stty_state = function()
	return io.popen([[stty --save]]):read('l')
end

local this
mt.new = function(args)
	if this then return this end	-- singleton. FIXME: put a warning? error?
	this = setmetatable({}, mt)
	this._state = stty_state()
	stty(args)
	return this
end

mt.__gc = function(this)
	stty(this._state)
end

return mt

